package com.gsit.expenditure.client.domina;



import javafx.beans.binding.DoubleBinding;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleLongProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import com.gsit.expenditure.domain.Customer;
import com.gsit.expenditure.domain.TravelBill;
import com.gsit.expenditure.domain.Vehicle;

import eu.schudt.javafx.controls.calendar.DatePicker;

public class TravelbillBean implements BeanHendler<TravelBill>{

	private ObjectProperty<Customer> customerName = new SimpleObjectProperty<Customer>() ;
	private ObjectProperty<Vehicle> vehicleName = new SimpleObjectProperty<Vehicle>();
	private StringProperty refNo = new SimpleStringProperty("");
	private StringProperty particulars = new SimpleStringProperty("");
	private DatePicker date = new DatePicker();
	
	private DoubleProperty distance = new SimpleDoubleProperty();
	private IntegerProperty days = new SimpleIntegerProperty();
	private StringProperty source = new SimpleStringProperty("");
	private StringProperty destination = new SimpleStringProperty("");
	private DoubleProperty rateProperty = new SimpleDoubleProperty();
	private DoubleProperty amount = new SimpleDoubleProperty();
	private LongProperty serialNumber = new SimpleLongProperty();
	

	private TravelBill travelBill;
	
	public TravelbillBean(TravelBill travelBill){
		if(travelBill == null){
			travelBill  = new TravelBill();
		}
		this.travelBill =travelBill;
		init(travelBill);
	}
	
	DoubleBinding binding=distance.multiply(rateProperty);	
	
	@Override
	public void init(TravelBill travelBill) {
		
		refNo.setValue(travelBill.getReferenceNumber());
		particulars.setValue(travelBill.getParticulars());
		distance.setValue(travelBill.getDistance());
		days.setValue(travelBill.getDays());
		source.setValue(travelBill.getSource());
		destination.setValue(travelBill.getDestination());
		rateProperty.setValue(travelBill.getRate());
		serialNumber.setValue(travelBill.getId());
		amount.setValue(binding.getValue());
		
	}


	
	@Override
	public void reLoad(TravelBill travelBill) {
		this.travelBill=travelBill;
		init(travelBill);
	}

	@Override
	public void clean() {
		
		refNo.setValue("");
		particulars.setValue("");
		distance.setValue(0.0);
		days.setValue(0);
		source.setValue("");
		destination.setValue("");
		rateProperty.setValue(0.0);
		amount.setValue(0.0);
			
			
		}


	@Override
	public TravelBill getObject() {
		
		travelBill.setCustomer(customerName.getValue());	
		System.out.println("TravelBillBean-Customer>>>>>>" + customerName.getValue());		
		travelBill.setVehicle(vehicleName.getValue());
		travelBill.setReferenceNumber(refNo.getValue());
		travelBill.setParticulars(particulars.getValue());
		travelBill.setDistance(distance.getValue());
		travelBill.setDays(days.getValue());
		travelBill.setSource(source.getValue());
		travelBill.setRate(rateProperty.getValue());
		travelBill.setDestination(destination.getValue());
		travelBill.setAmount(binding.getValue());
		travelBill.setId(serialNumber.getValue());
		System.out.println("SerialNumber>>>>>>>>>>>>"+serialNumber.getValue());
		System.out.println("Total Amount>>>>>>>>>>"+binding.getValue());
		return travelBill;
		
	}
	
	
	
	
	public LongProperty getSerialNumber() {
		return serialNumber;
	}

	public void setSerialNumber(LongProperty serialNumber) {
		this.serialNumber = serialNumber;
	}

	private ObjectProperty<Vehicle>  selectedVehicle = new SimpleObjectProperty<Vehicle>(); 
	
	public ObjectProperty<Vehicle> getSelectedVehicle() {
		return selectedVehicle;
	}



	public void setSelectedVehicle(ObjectProperty<Vehicle> selectedVehicle) {
		this.selectedVehicle = selectedVehicle;
	}

	public DoubleBinding getBinding() {
		return binding;
	}



	public void setBinding(DoubleBinding binding) {
		this.binding = binding;
	}



	public void setRateProperty(DoubleProperty rateProperty) {
		this.rateProperty = rateProperty;
	}

	
	

	public StringProperty getRefNo() {
		return refNo;
	}

	public void setRefNo(StringProperty refNo) {
		this.refNo = refNo;
	}

	public StringProperty getParticulars() {
		return particulars;
	}

	public void setParticulars(StringProperty particulars) {
		this.particulars = particulars;
	}

	public DatePicker getDate() {
		return date;
	}

	public void setDate(DatePicker date) {
		this.date = date;
	}

	public DoubleProperty getDistance() {
		return distance;
	}

	public void setDistance(DoubleProperty distance) {
		this.distance = distance;
	}

	public StringProperty getSource() {
		return source;
	}

	public void setSource(StringProperty source) {
		this.source = source;
	}

	public StringProperty getDestination() {
		return destination;
	}

	public void setDestination(StringProperty destination) {
		this.destination = destination;
	}

	
	public TravelBill getTravelBill() {
		return travelBill;
	}

	public void setTravelBill(TravelBill travelBill) {
		this.travelBill = travelBill;
	}

	public IntegerProperty getDays() {
		return days;
	}

	public void setDays(IntegerProperty days) {
		this.days = days;
	}

	public DoubleProperty getRateProperty() {
		return rateProperty;
	}

	public void setRate(Double rate) {
		this.rateProperty.set(rate);
	}

	public DoubleProperty getAmount() {
		return amount;
	}

	public void setAmount(DoubleProperty amount) {
		this.amount = amount;
	}

	public ObjectProperty<Vehicle> getVehicleName() {
		return vehicleName;
	}

	public void setVehicleName(ObjectProperty<Vehicle> vehicleName) {
		this.vehicleName = vehicleName;
	}



	public ObjectProperty<Customer> getCustomerName() {
		return customerName;
	}
	public void setCustomerName(ObjectProperty<Customer> customerName) {
		this.customerName = customerName;
	}




	



	
}
